<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="./css/bootstrap.css">
    <style>
        #show {
            background-color: #eeeeee;
            width: 100%;
            height: 200px;
            padding-top: 40px;
            margin-top: 25px;
            padding-right: 30px;
        }

        #show h1 {
            margin-left: 40px;
        }

        .navbar-default .navbar-nav>.active>a {
            background: none;
        }

        .inner {
            border: none;
        }

        .label {
            width: 60px;
            height: 40px;
            border: none;
        }
    </style>
</head>

<body>
    <div id="app">
        <nav class="navbar navbar-default">
            <div class="container-fluid">
                <!-- Brand and toggle get grouped for better mobile display -->
                <div class="navbar-header">
                    <a class="navbar-brand" href="#">云题库</a>
                </div>
                <!-- Collect the nav links, forms, and other content for toggling -->
                <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                    <ul class="nav navbar-nav">
                        <li class="active">
                            <router-link to="/home" href="#">首页</router-link>
                        </li>
                        <li>
                            <router-link to="/aboutUs" href="#">关于我们</router-link>
                        </li>
                        <li class="dropdown">
                            <router-link to="/account" href="#" class="dropdown-toggle" data-toggle="dropdown"
                                role="button" aria-haspopup="true" aria-expanded="false">账户中心 <span
                                    class="caret"></span></router-link>
                            <ul class="dropdown-menu">
                                <router-link to="/account/pwd" href="#">密码</router-link>
                            </ul>
                        </li>
                    </ul>
                </div><!-- /.navbar-collapse -->
            </div><!-- /.container-fluid -->
        </nav>
        <div class="btn-group">
            <button class="label label-primary" @click='back()'>后退</button>
            <button class="label label-primary" @click='go()'>前进</button>
            <button class="label label-primary" @click='back2()'>跳步-2</button>
            <button class="label label-primary" @click='toindex()'>push</button>
            <button class="label label-primary" @click='replace()'>replace</button>
        </div>
        <div id="show">
            <!-- 内容展示区域(占位符) -->
            <router-view></router-view>
        </div>
    </div>
    <template id="account">
        <div>
            <h1>账户中心</h1>
            <router-view></router-view>
        </div>
    </template>
</body>
<script src="./js/jquery.min.js"></script>
<script src="./js/bootstrap.js"></script>
<script src="./js/vue.js"></script>
<script src="./js/vue-router.js"></script>
<script>
    // 1.组件
    let Home = Vue.extend({ template: "<h1>首页</h1>" });
    let AboutUs = { template: "<h1>关于我们</h1>" };
    let Accountt = { template: "#account" };
    // let Login = {template:"<h1>登录</h1>"};

    // 2.配置页面的路径信息(多个)
    let routes = [
        { path: '/home', component: Home },
        { path: '/aboutUs', component: AboutUs },
        {
            path: '/account', component: Accountt, children: [
                { path: "pwd", component: { template: "<h1>密码</h1>" } },
            ]
        },
        // {path:"/login",component:Login}
    ]

    // 创建路由对象 VueRouter
    let router = new VueRouter({
        routes
    })

    let vm = new Vue({
        el: "#app",
        // 配置路由
        router,
        methods: {
            back() {
                this.$router.go(-1)
            },
            go() {
                this.$router.go(1)
            },
            back2() {
                this.$router.go(-2)
            },
            toindex() {
                this.$router.push({
                    path: '/home'
                })
            },
            replace() {
                this.$router.replace('/home')
            }
        }
    })
</script>

</html>